/**
 * @author attilax 老哇的爪子
\t@since  Aug 2, 2014 3:18:22 AM$
 */
package com.attilax.io;

import com.attilax.Closure;
import com.attilax.core;
import com.attilax.exception.ExUtil;
import com.attilax.io.filex;
import com.attilax.lang.text.strUtil;
import com.attilax.office.excelUtil;
import com.attilax.util.dirx;
import com.attilax.util.fileC0;





import com.google.common.collect.Lists;

import static com.attilax.core.*;

import java.util.*;
import java.util.concurrent.Callable;
import java.util.function.Function;
import java.net.*;
import java.io.*;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

/**
 * @author attilax 老哇的爪子
 * @since Aug 2, 2014 3:18:22 AM$
 */
public class FileLineTraver {

	/**
	 * @author attilax 老哇的爪子 \t@since Aug 2, 2014 3:18:22 AM$
	 * 
	 * @param args
	 */
	public static Logger logger = Logger.getLogger("traver");

	public static void main(String[] args) throws IOException {

		String strPath = "C:\\Users\\Administrator.ATTILAXPC188\\Documents\\[ atian inputmethod ]\\导出 - 全部词条.txt";
		FileLineTraver.trav(strPath, "unicode", (line)->{
			String[] a=line.toString().split("\t");
		
			if(	a.length<2 )
				return line;
 
			String forighCodePix=a[1];
			ArrayList<String> newArrayList = Lists.newArrayList(",","#");
			String[] forighCode_arr=strUtil.splitByMultiChar(forighCodePix,newArrayList) ;
			
			String forighCode=forighCode_arr[0];
			if(!StringUtils.isAlpha(forighCode))
				System.out.println(line);
			return line;
			
			
		});
	//	trav(strPath, "c:\\vodfiles.txt");
		// attilax 老哇的爪子 3:18:22 AM Aug 2, 2014
		// System.out.println("@f".replace("@f", "c:\\aa.aa"));
		// long start = new Date().getTime();
		// trav();
		// long end = new Date().getTime();
		// System.out.println("--pass::" + String.valueOf(end - start));
		// MySqlClass mc=new MySqlClass("dbc8","root","");
		//
		// mc.executeUpdate(sql);
		//
		// {
		// System.out.println("--");
		// }
		System.out.println("--f");
	}

	// attilax 老哇的爪子 3:18:22 AM Aug 2, 2014

	public static void trav(String strPath, String encode, Function lineRunner) {
	//	Function<T, R>
		// final String fileName = "c:\\clraft.sql";
		final CharSequence tab = "folderCountClraftr";
		filex fc = null;
		try {
			fc = new filex(strPath);
		} catch (IOException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
			ExUtil.throwEx(e2);
		}

		StringBuilder sb = new StringBuilder();
		InputStreamReader isr = null;
		try {
			isr = new InputStreamReader(new FileInputStream(strPath), encode);
		} catch (Exception e1) {

			e1.printStackTrace();
			ExUtil.throwEx(e1);
		}
		BufferedReader reader;
		ArrayList li = new ArrayList<String>();
		reader = new BufferedReader(isr);

	 	while (true) {
			try {
				String  	line = reader.readLine();
				if(line==null)
					break;
				lineRunner.apply(line);
			} catch (Exception e) {

				e.printStackTrace();
				ExUtil.throwEx(e);
			}
		 
		 
			
		}

		// o4e cancel occu handel
		try {
			isr.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		try {
			fc.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	/**
	 * for compare tree /a ....perf test
	 * 
	 * @author attilax 老哇的爪子 \t@since Aug 2, 2014 8:16:57 AM$
	 * 
	 * @throws IOException
	 */
	@Deprecated
	private static void trav2() throws IOException {
		final String fileName = "c:\\sql.txt.sql";
		final filex fc = new filex(fileName);
		dirx.trave("G:\\ati\\doc", new Closure() {

			@Override
			public Object execute(Object arg0) throws Exception {
				// attilax 老哇的爪子 3:46:39 AM Aug 2, 2014

				{

					fc.append_HP(arg0.toString() + ";\r\n");

					return null;
				}

			}
		});
		fc.close();
	}
}

// attilax 老哇的爪子